﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HQPadMVC.Models;

namespace HQPadMVC.Controllers
{ 
    public class SkillRequirementController : Controller
    {
        private HQContext db = new HQContext();

        //
        // GET: /SkillRequirement/

        public ViewResult Index(int? SkillID)
        {
            var skillRequirements =
                db.SkillRequirements
                .Include(s => s.Skill)
                .Include(s => s.Guilds)
                .Where(s => s.SkillID == SkillID);

            return View(skillRequirements.ToList());
        }

        //
        // GET: /SkillRequirement/Details/5

        public ViewResult Details(int id)
        {
            SkillRequirement skillrequirement = db.SkillRequirements.Find(id);
            return View(skillrequirement);
        }

        //
        // GET: /SkillRequirement/Create

        public ActionResult Create()
        {
            ViewBag.SkillID = new SelectList(db.Skills, "SkillID", "Name");
            ViewBag.GuildID = new SelectList(db.Guilds, "GuildID", "Name");
            return View();
        } 

        //
        // POST: /SkillRequirement/Create

        [HttpPost]
        public ActionResult Create(SkillRequirement skillrequirement)
        {
            if (ModelState.IsValid)
            {
                db.SkillRequirements.Add(skillrequirement);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.SkillID = new SelectList(db.Skills, "SkillID", "Name", skillrequirement.SkillID);
            ViewBag.GuildID = new SelectList(db.Guilds, "GuildID", "Name", skillrequirement.GuildID);
            return View(skillrequirement);
        }
        
        //
        // GET: /SkillRequirement/Edit/5
 
        public ActionResult Edit(int id)
        {
            SkillRequirement skillrequirement = db.SkillRequirements.Find(id);
            ViewBag.SkillID = new SelectList(db.Skills, "SkillID", "Name", skillrequirement.SkillID);
            ViewBag.GuildID = new SelectList(db.Guilds, "GuildID", "Name", skillrequirement.GuildID);
            return View(skillrequirement);
        }

        //
        // POST: /SkillRequirement/Edit/5

        [HttpPost]
        public ActionResult Edit(SkillRequirement skillrequirement)
        {
            if (ModelState.IsValid)
            {
                db.Entry(skillrequirement).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.SkillID = new SelectList(db.Skills, "SkillID", "Name", skillrequirement.SkillID);
            ViewBag.GuildID = new SelectList(db.Guilds, "GuildID", "Name", skillrequirement.GuildID);
            return View(skillrequirement);
        }

        //
        // GET: /SkillRequirement/Delete/5
 
        public ActionResult Delete(int id)
        {
            SkillRequirement skillrequirement = db.SkillRequirements.Find(id);
            return View(skillrequirement);
        }

        //
        // POST: /SkillRequirement/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            SkillRequirement skillrequirement = db.SkillRequirements.Find(id);
            db.SkillRequirements.Remove(skillrequirement);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}